<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h1,ul {
            text-align: center;
        }

        .box {
            width: 200px;
            height: 300px;
            background-color: pink;
        }
        ul>li{
            
            list-style: none;
        }
    </style>
</head>

<body>
    <h1>距离五一放假还有^_^</h1>
    <ul>
        <li class="day"></li>天
        <li class="hour"></li>时
        <li class="minute"></li>分
        <li class="second"></li>秒
    </ul>

    <div class="box"></div>
</body>
<script>
    var time = new Date('2021-5-1 00:00:00')
    var timer=time.getTime()
    console.log(time);
    var day=document.querySelector('.day')
    var hour=document.querySelector('.hour')
    var minute=document.querySelector('.minute')
    var second=document.querySelector('.second')
    // console.log(day);
    // day.innerText='sds'
    
    setInterval(() => {
        var nowTime = new Date()
        // console.log(nowTime);
        var nowTimer=nowTime.getTime()
        var jiange=Math.abs(Math.round((nowTimer-timer)/1000))
        // console.log(jiange);
        var Day=parseInt(jiange/(60*60*24))
        day.innerText=Day
        // console.log(Day);
        var Hours=parseInt(jiange%(60*60*24)/(60*60))
        // console.log(Hours);
        hour.innerText=Hours
        var Minutes=parseInt(jiange%(60*60)/60)
        // console.log(Mnutes);
        minute.innerText=Minutes
        var Seconds=parseInt(jiange%60)
        // console.log(Seconds);
        second.innerText=Seconds
    }, 1000);

    //随即生成0-10之间的整数
    //Math.round()四舍五入
    // var num=Math.round(Math.random()*10)
    // console.log(num);
    //Math.floor()向下取整
    // var obj={}
    // for(var i=0;i<100000;i++){
    //     //var num=Math.round(Math.random()*10)//此种情况会导致0和10出现次数较少
    //     var num=Math.floor(Math.random()*11)
    //     if(obj[num]){
    //         obj[num]++
    //     }else{
    //         obj[num]=1
    //     }

    // }
    // console.log(obj);


    //情景二：获取10-20之间
    var res = Math.floor(Math.random() * 11) + 10
    console.log(res);

    //取n-m之间的整数
    var n = 1
    var m = 12
    var obj = {}
    for (var i = 0; i < 100000; i++) {
        //var num=Math.round(Math.random()*10)//此种情况会导致0和10出现次数较少
        var num = Math.floor(Math.random() * (m - n + 1)) + n
        if (obj[num]) {
            obj[num]++
        } else {
            obj[num] = 1
        }

    }
    console.log(obj);


    //封装函数
    function suiji(a, b) {
        var max = Math.max(a, b)
        var min = Math.min(a, b)
        var res = Math.floor(Math.random() * (max - min + 1) + min)
        return res
    }
    console.log(suiji(8, 5));
</script>

</html>